﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include <string>
#include <vector>
#include <memory>
#include "GmFamilyDataStandard.h"

namespace gfam
{
    class IFamilySoftwareVersion;
    class IFamilyDataStandardVersion;
    class IFamilyDirectory;
    class IFamilyPropertyDefinition;

    // \brief 数据标准领域服务接口
    class GM_FAMILY_DATA_STANDARD_EXPORT IFamilyDataStandardService
    {
    public:
        virtual ~IFamilyDataStandardService() = 0 {}

        /// \brief 返回数据标准服务的全局实例
        /// 
        /// \return 返回全局实例
        static std::shared_ptr<IFamilyDataStandardService> GlobalInstance();

        /// \brief 启用内建缓存
        /// 
        /// \return 是否成功
        virtual bool EnableBuiltinCache() = 0;

        /// \brief 执行异步数据更新
        /// 
        /// \param callback 更新完成后的回调函数
        /// \return 返回是否启动成功
        virtual bool UpdateAsync(const std::wstring& paramodelVersion, const std::function<void()>& callback = std::function<void()>()) = 0;

        /// \brief 等待异步数据更新完成
        /// 
        virtual void WaitForUpdateFinished() = 0;

        /// \brief 执行同步数据更新
        /// 
        /// \return 返回是否启动成功
        virtual bool UpdateSync(const std::wstring& paramodelVersion) = 0;

        /// \brief 获取所有的软件版本
        /// 
        /// \return 返回是软件版本列表
        virtual std::vector<std::shared_ptr<IFamilySoftwareVersion>> GetAllSoftwareVersion() const = 0;
        
        /// \brief 获取软件版本号
        /// 
        /// \return 返回是软件号
        virtual std::wstring GetSoftwareVersionBySoftwareCode(const std::wstring& softwareCode) const = 0;

        /// \brief 根据类别的uid反查所属软件版本
        /// 
        /// \param directoryUid 类别Uid
        /// \return 返回软件版本
        virtual std::shared_ptr<IFamilySoftwareVersion> GetSoftwareByDirectoryUid(const std::wstring& directoryUid) const = 0;
        
        /// \brief 根据软件版本下对应的最新数据标准版本
        /// 
        /// \param softwareCode 软件code
        /// \param softwareVersion 软件版本
        /// \return 返回最新的数据标准版本
        virtual std::shared_ptr<IFamilyDataStandardVersion> GetLastDataStandardVersion(const std::wstring& softwareCode, const std::wstring& softwareVersion) const = 0;
        
        /// \brief 根据Uid查询类别
        /// 
        /// \param uid 类别Uid
        /// \return 返回类别对象
        virtual std::shared_ptr<IFamilyDirectory>  GetDirectory(const std::wstring& uid) const = 0;
        
        /// \brief 查询数据标准版本下的所有类别
        /// 
        /// \param dataStandardCode 数据标准code
        /// \param dataStandardCodeVersion 数据标准版本
        /// \return 返回类别对象列表
        virtual std::vector<std::shared_ptr<IFamilyDirectory>> GetAllLeafDirectories(const std::wstring& dataStandardCode, const std::wstring& dataStandardCodeVersion) const = 0;
        
        /// \brief 查询数据标准版本下根分类
        /// 
        /// \param dataStandardVersion 数据标准对象
        /// \return 返回分类对象
        virtual std::vector<std::shared_ptr<IFamilyDirectory>> GetRootDirectories(const std::shared_ptr<IFamilyDataStandardVersion>& dataStandardVersion) const = 0;
        
        /// \brief 查询分类的子分类
        /// 
        /// \param directory 分类对象
        /// \return 返回子分类对象列表
        virtual std::vector<std::shared_ptr<IFamilyDirectory>> GetSubDirectories(const std::shared_ptr<IFamilyDirectory>& directory) const = 0;
        
        /// \brief 查询类别下的属性定义列表
        /// 
        /// \param directoryUid 类别uid
        /// \return 返回属性定义列表
        virtual std::vector<std::shared_ptr<IFamilyPropertyDefinition>> GetPropertyDefinitionList(const std::wstring& directoryUid) const = 0;

        /// \brief 查询属性定义
        /// 
        /// \param uid 属性定义uid
        /// \return 返回属性定义，没有则返回空
        virtual std::shared_ptr<IFamilyPropertyDefinition> GetPropertyDefinitionByUid(const std::wstring& uid) const = 0;
    };
}